﻿<UserControl x:Class="GSF.PhasorProtocols.UI.UserControls.DeviceListUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="850"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls;assembly=GSF.TimeSeries.UI.WPF"
             xmlns:tsfBinding="clr-namespace:GSF.TimeSeries.UI.Binding;assembly=GSF.TimeSeries.UI"
             Background="Transparent">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical">

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <TextBox x:Name="TextBoxSearch" Width="125"/>
            <Button Content="Search" Command="{Binding Path=SearchCommand}" CommandParameter="{Binding ElementName=TextBoxSearch, Path=Text}" ToolTip="Search devices" Margin="2" IsDefault="True"/>
            <Button Content="Show All" Command="{Binding Path=ShowAllCommand}" ToolTip="Show all devices" Margin="2"/>
        </StackPanel>
        
        <sdk:DataGrid x:Name="DataGridList" ItemsSource="{Binding CurrentPage}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" SelectedIndex="{tsfBinding:Column Path=CurrentSelectedIndex}"
                      PreviewKeyDown="DataGrid_PreviewKeyDown" Sorting="DataGrid_Sorting" CellEditEnding="DataGrid_CellEditEnding">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTemplateColumn Header="Acronym" Width="3*" SortMemberPath="Acronym">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Template="{StaticResource HyperlinkStyleButtonTemplate}" Content="{tsfBinding:Column Path=Acronym}" 
                                    Command="{tsfBinding:GridButtonCommand Path=DataContext.EditCommand}" 
                                    CommandParameter="{tsfBinding:GridButtonCommand Path=DataContext.CurrentItem}" ToolTip="{Binding Path=Name}" Width="Auto" />
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
                <sdk:DataGridCheckBoxColumn Header="Concentrator" Width="2*" Binding="{tsfBinding:Column Path=IsConcentrator}" CellStyle="{StaticResource CenterAlignCellStyle}" IsReadOnly="True"/>
                <sdk:DataGridTemplateColumn Header="Enabled" Width="*" SortMemberPath="Enabled" >
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{tsfBinding:Column Path=Enabled}" HorizontalAlignment="Center" Click="DataGridEnabledCheckBox_Click"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
                <!--<sdk:DataGridCheckBoxColumn Header="Enabled" Width="*" Binding="{tsfBinding:Column Path=Enabled}" CellStyle="{StaticResource CenterAlignCellStyle}" />-->
                <sdk:DataGridTemplateColumn Width="*">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Template="{StaticResource HyperlinkStyleButtonTemplate}" Content="Phasors" 
                                    Command="{tsfBinding:GridButtonCommand Path=DataContext.PhasorCommand}" 
                                     Width="Auto"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
                <sdk:DataGridTemplateColumn Width="1.5*">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Template="{StaticResource HyperlinkStyleButtonTemplate}" Content="Measurements" 
                                    Command="{tsfBinding:GridButtonCommand Path=DataContext.MeasurementCommand}" 
                                    Width="Auto"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
                <sdk:DataGridTemplateColumn Width="*">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                <Button ToolTip="Update Configuration" Command="{tsfBinding:GridButtonCommand Path=DataContext.UpdateConfigurationCommand}" 
                                    CommandParameter="{tsfBinding:GridButtonCommand Path=DataContext.CurrentItem}" Width="Auto" Margin="2" >

                                    <Button.Visibility>
                                        <Binding Path="ParentID" Converter="{StaticResource ObjectToVisibilityConverter}">
                                            <Binding.ConverterParameter>
                                                <sys:Boolean>True</sys:Boolean>
                                            </Binding.ConverterParameter>
                                        </Binding>
                                    </Button.Visibility>

                                    <Image Source="/GSF.TimeSeries.UI;component/images/EditConfiguration.png" Height="16" Width="16" />
                                    
                                </Button>
                                <Button ToolTip="Make Copy" Command="{tsfBinding:GridButtonCommand Path=DataContext.CopyCommand}" 
                                    CommandParameter="{tsfBinding:GridButtonCommand Path=DataContext.CurrentItem}" Width="Auto" Margin="2">
                                <Image Source="/GSF.TimeSeries.UI;component/images/Copy.png" Height="16" Width="16" />
                            </Button>
                            </StackPanel>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

        <uc:DataPagerUserControl Grid.Row="1"  CurrentPageNumber="{Binding CurrentPageNumber}" PageCount="{Binding PageCount}"
                                 FirstCommand="{Binding FirstCommand}" PreviousCommand="{Binding PreviousCommand}"
                                 NextCommand="{Binding NextCommand}" LastCommand="{Binding LastCommand}" VerticalAlignment="Bottom"/>
    </StackPanel>
</UserControl>
